package com.gmzg.gmzgoffice.message;

import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.gmzg.gmzgoffice.R;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.ui.EaseChatFragment;

public class ChatActivity extends AppCompatActivity {

    private String mToUserName;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);

        Intent intent = getIntent();
        mToUserName = intent.getStringExtra("toUserName");

        int type = intent.getIntExtra("type", EaseConstant.CHATTYPE_SINGLE);

        if(mToUserName == null){
            finish();
        }else{
            // 1. 使用 EaseUI 中的聊天Fragment, 需要设置参数；
            EaseChatFragment fragment = new EaseChatFragment();
            Bundle args = new Bundle();
            // 1.1 设置给哪一个用户发送消息
            args.putString(EaseConstant.EXTRA_USER_ID, mToUserName);
            // 1.2 设置当前的聊天的类型，私聊，群聊，聊天室
            args.putInt(EaseConstant.EXTRA_CHAT_TYPE, type);
            fragment.setArguments(args);

            // 2. 显示Fragment
            FragmentManager manager = getSupportFragmentManager();
            FragmentTransaction tx = manager.beginTransaction();
            tx.replace(R.id.chat_fragment_container, fragment);
            tx.commit();
        }
    }
}
